from flask import jsonify, request
from flask.views import MethodView
from app.models.companys import Companys
from webargs import fields
from webargs.flaskparser import parser


parser_args = {
    'page': fields.Int(missing=0, error_messages={'invalid': '必须是数值类型'})
}


class CompanysAPI(MethodView):
    def get(self):
        """获取系统
        """
        args = parser.parse(parser_args, request)
        query = Companys.query
        data = Companys.to_collection_dict(query, args['page'], 20)
        return jsonify(success=True, data=data)
